{% extends "base.html" %} {% block head %} {{ super() }}
<script src="{{url_for('static', filename='../static/js/control/ztable.js')}}" type="text/javascript" charset="utf-8"></script>
<script src="{{url_for('static', filename='../static/js/control/zform.js')}}" type="text/javascript" charset="utf-8"></script>
<script src="{{url_for('static', filename='../static/js/control/zui.js')}}" type="text/javascript" charset="utf-8"></script>

<script src="{{url_for('static', filename='../static/js/app/Spec.js')}}" type="text/javascript" charset="utf-8"></script>
<script src="{{url_for('static', filename='../static/datepicker/js/bootstrap-datepicker.js')}}" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="../static/datepicker/css/datepicker.css" type="text/css" media="screen" />

<script>
	$(document).ready(function(){
		
		var defaults = {{ defaults | safe }};
		
		var $SpecForm = $('#spec-form').ZForm({
			//errors:{{ errors_json | safe }}
		});
		
		var $SprintViewTab = $('#sprint-view-tabs').ZTab();
		
		function select_sprint($Row){
			var sid = $Row.attr('row_id');
			var _tab = $SprintViewTab.getActiveTab();
			
			$SpecForm.setFieldByName("sprint_id", sid);
			
			if ($(_tab).find('a').attr("href")=="#sprint-info-tab"){
				$.post('/get_sprint', { sid: sid} ).done(
						function(data){
							var sprint = $.parseJSON(data.sprint);
							
							var $InfoPanel = $('#sprint-info-panel').find('.panel-body').empty();
							$InfoPanel.append($('<p></p>').text(sprint['name']));
							$InfoPanel.append($('<p></p>').text(sprint['description']));
							$InfoPanel.append($('<p></p>').text('plan from:' + sprint['start-date'] + ' to:' + sprint['end-date']));
						});
			}else if ($(_tab).find('a').attr("href")=="#sprint-specs-tab"){
			
				$.post('/get_specs', { sprint_id: sid}).done(
						function(data){
							var _specs = $.parseJSON(data.specs);
							$SpecList.reload(_specs);
						});
			}
		}
		
		var $SprintList = $('#l-sprint-list').ZTable({
			columns:{'name':'Name'},
			datas:{{ sprints | safe }},
			with_title:false,
			select_row_cb: select_sprint,
			row_id: defaults['sprint_id']});
		
		function select_spec($Row){
		}

		var $SpecList = $('#spec-list').ZTable({
			columns:{'name':'Name','description':'Description'},
			datas:{{ specs | safe }},
			select_row_cb: select_spec});

		var spec_panel = new SpecPanel('sprint-specs-tab', $SprintList, $SpecList, $SpecForm);
		
		// API
		// getProjectId from tree
		
	});
	</script>
{% endblock %}


{% block breadcrumb %}
	{{ super() }}
{% endblock %}

{% block content %}
		<div class="left-area col-sm-2">
			<table id="l-sprint-list"></table>
		</div>

		<div class="main-area col-sm-10">
			<ul id="sprint-view-tabs" class="nav nav-tabs">
			  <li class="z-tab"><a href="#sprint-specs-tab" data-toggle="tab">Specifications</a></li>
			  <li class="z-tab"><a href="#sprint-info-tab" data-toggle="tab">Sprint</a></li>
			</ul>
			<div class="tab-content">
				<div class="tab-pane fade" id="sprint-info-tab">
					<div id="toolbar-row" class="row z-toolbar col-sm-12">
						<div class="btn-toolbar col-xs-10 col-sm-8">
							<button class="btn btn-primary col-md-2 z-btn-new" data-toggle="modal" data-target="#sprint_dialog">New</button>
							<button class="btn btn-primary col-md-2 z-btn-edit" data-toggle="modal" data-target="#sprint_dialog">Edit</button>
							<button class="btn btn-primary col-md-2">Delete</button>
							<button class="btn btn-primary col-md-2 z-btn-submit">Submit</button>
						</div>
					</div>
					
					<div id='sprint-info-panel' class="row z-panel col-sm-12">
						<div class="panel panel-default z-panel">
							  <div class="panel-body">
							  </div>
						</div>
					</div>
					
					<div class="row z-panel col-sm-12">
						<div class="panel panel-default z-panel">
							  <div class="panel-body">
							  	Comment-1
							  </div>
						</div>
					</div>
					
				</div>
				<div class="tab-pane fade" id="sprint-specs-tab">
					<div id="toolbar-row" class="row z-toolbar col-sm-12">
						<div class="btn-toolbar col-xs-10 col-sm-8">
							<button class="btn btn-primary col-md-2 z-btn-new" data-toggle="modal" data-target="#spec_dialog">New</button>
							<button class="btn btn-primary col-md-2 z-btn-edit" data-toggle="modal" data-target="#spec_dialog">Edit</button>
							<button class="btn btn-primary col-md-2 z-btn-del">Delete</button>
							<a class="btn btn-primary col-md-2 z-btn-specs" href="/spec_view">Spec View</a>
						</div>
					</div>
					
					<div class="row z-panel col-sm-12">
						<div class="panel panel-default z-panel">
							  <div class="panel-body">
							  	<table id="spec-list"></table>
							  </div>
						</div>
					</div>

				</div>
			</div><!-- end of .tab-content -->
		</div><!-- end of .main-area -->


	
	<!-- Modal Dialog -->
	<div class="modal fade" id="spec_dialog" tabindex="-1" role="dialog" aria-hidden="true">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        <h4 class="modal-title">Specification</h4>
	      </div>
	      
	      
	      <form id="spec-form" onsubmit="return false;">
	      <div class="modal-body">
				
				
				<div class="row form-group">
					<div class="z-label col-md-2">{{ 'Name' }}</div>
					<div class="col-md-7">
						<input class="form-control" type="text" name="name" placeholder="{{ 'Specification name' }}" />
					</div>
					<div class="col-md-3 z-hint"></div>
				</div>
		
				<div class="row form-group">
					<div class="z-label col-md-2">{{ 'Description' }}</div>
					<div class="col-md-7">
						<textarea class="form-control" rows="5" name="description" placeholder="{{ 'Enter description' }}"></textarea>
					</div>
					<div class="col-md-3 z-hint"></div>
				</div>
		
				<div class="row form-group" >
					<div class="z-label col-md-2">{{ 'Plan' }}</div>
					<div class="col-md-3">
						<input class="form-control" name="start-date" data-date-format="mm/dd/yyyy" placeholder="{{ 'Start date' }}">
					</div>
					<div class="col-md-4 input-group">
						<span class="input-group-addon">to</span>
						<input class="form-control" name="end-date" data-date-format="mm/dd/yyyy" placeholder="{{ 'End date' }}">
					</div>
					<div class="col-md-3 z-hint"></div>
				</div>
		
				<input class="hide" type="text" name="mode" />
				<input class="hide" type="text" name="sprint_id" />
				<input class="hide" type="text" name="id" />
				<input class="hide" type="text" name="created" />
			
	
	      </div>
	      <div class="modal-footer">
	        <button class="btn btn-default" data-dismiss="modal">Close</button>
	        <button class="btn btn-primary z-btn-submit">Save changes</button>
	      </div>
	      
	      </form>
	      
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
	
{% endblock %}

{% block right_area %}
	<div class="right-side-area">
	</div>
{% endblock %}


